var request = require('request'),
	cheerio = require('cheerio'),
	baseUrl = 'http://www.nasdaq.com/earnings/report/{0}',
	ticker = process.argv[2],
	url = baseUrl.replace('{0}', ticker),
	headers = { 
		'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'
	};
	
request.get({url: url, headers: headers}, function(err, resp, body) {
	var $ = cheerio.load(body),
		$trs = $('#left-column-div .genTable tr'),
		dates = [],
		datesString;

	$trs = $trs.slice(1, 5);
	
	$trs.each(function(i, tr){
		var $tds = $(tr).find('td'),		
			date = $($tds.get(1)).text();
		
		dates.push(date);
	});

	datesString = JSON.stringify(dates);
	console.log(datesString);
});